﻿using Microsoft.EntityFrameworkCore;
using System;
using TradeDataAPI.Core.Extensions.AutofacManager;

namespace TradeDataAPI.Core.EFDbContext
{
    public class MySqlContext : VOLContext, IDependency
    {
        /// <summary>
        /// 数据库连接名称 
        /// </summary>
     //   public string DataBaseName = null;
        public MySqlContext()
                : base()
        {
        }
        public MySqlContext(string connction)
            : base()
        {
            DataBaseName = connction;
        }

        public override void Dispose()
        {
            base.Dispose();
        }
        public override int SaveChanges()
        {
            try
            {
                return base.SaveChanges();
            }
            catch (Exception ex)//DbUpdateException 
            {
                throw (ex.InnerException ?? ex);
            }
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            base.isMysql = true;
            ////默认禁用实体跟踪
            //optionsBuilder = optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);

            base.OnConfiguring(optionsBuilder);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }
    }
}
